# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=syslinux
pkgver=6.04_pre1
pkgrel=6
_ver=${pkgver/_/-}
pkgdesc="Boot loader for the Linux operating system"
url="http://syslinux.org"
arch="x86 x86_64"
license="GPL"
makedepends="linux-headers nasm perl util-linux-dev gnu-efi-dev"
depends="mtools blkid mkinitfs"
triggers="syslinux.trigger=/boot"
install="syslinux.post-upgrade"
options="textrels"
ldpath="/usr/share/syslinux"

source="https://www.kernel.org/pub/linux/utils/boot/syslinux/Testing/${pkgver%_pre*}/syslinux-$_ver.tar.xz
	update-extlinux.conf
	update-extlinux
	0018-prevent-pow-optimization.patch
	fix-sysmacros.patch
	"
subpackages="$pkgname-doc $pkgname-dev"

_loaderarch=
case "$CARCH" in
x86)	_loaderarch=efi32;;
x86_64)	_loaderarch=efi64;;
esac

builddir="$srcdir"/$pkgname-$_ver
prepare() {
	cd "$builddir"
	for i in $source; do
		i=${i%%::*}
		case "$i" in
		*.patch) msg $i; patch -p1 -i "$srcdir"/$i || return 1;;
		esac
	done
}

build() {
	cd "$builddir"
	unset LDFLAGS
	make $_loaderarch installer || return 1
}

package() {
	cd "$builddir"
	make -j1 INSTALLROOT="$pkgdir" MANDIR=/usr/share/man \
		bios $_loaderarch install || return 1

	mkdir -p "$pkgdir"/etc/update-extlinux.d
	cp "$srcdir"/update-extlinux.conf "$pkgdir"/etc/
	sed "/^version=/s/=.*/=$pkgver-r$pkgrel/" "$srcdir"/update-extlinux \
		> "$pkgdir"/sbin/update-extlinux
	chmod 755 "$pkgdir"/sbin/update-extlinux
}

sha512sums="7927dd39be8e2dcf4138a6fea33def67d19d938379d694f15b48fdd2f5924c028b7a9e7bd71d0c7c6630c203e9e2a54296628e530632ad5e6f55b1ebefe8fc98  syslinux-6.04-pre1.tar.xz
9d2b82c91525de584daad6b0c0e2df5d13092c47e91a812e26405f5ff78d4587a8ae7f7a8590124687307f83efb15f686e4090193adc7b4e3601a4200f9283cd  update-extlinux.conf
bfeb911507c079c8b01027a7823e562d81100b1fcd0786c707ad33c5ce18fa0eb6d6db34bc7b6cbbc419248188970cebe8286345f4aa3662d16644c51f50b98c  update-extlinux
92fa48133ef702092d7acafae0e0e20f9355cd2b5fe199b96fcccba5a1e688c360de4d069391815255f5493228ad03998d20b99748323396d20d12a1f27c60cd  0018-prevent-pow-optimization.patch
6fb63b50a6c746445a58badc81cbf8525f38e2a7868b97ac21aa9d20c162f2318fab6c25505614700033a840aa5c06c3cef3065f11b5b5f4e514474194ff4b54  fix-sysmacros.patch"
